//: [Previous](@previous)

import Foundation


//写一个简单的函数,接受两个参数,返回一个字符串
func greet(name:String,withGreeting greeting:String) -> String{
    return "\(greeting) \(name)"
}

let personalGreeting = greet(name:"Matt",withGreeting:"hello,")
print(personalGreeting)


//写一个返回函数的函数
func greeting(forName name:String) -> (String) -> String {
    func greeting(_ greeting:String) -> String{
        return "\(greeting) \(name)"
    }
    return greeting(_:)
}

let greetMattWith = greeting(forName: "Matt")
let mattGreeting = greetMattWith("hello,")
print(mattGreeting)


//创建一个结构体Person
struct Person {
    var firstName = "Matt"
    var lastName = "Mathias"
    
    mutating func changeTo(firstName:String,lastName:String){
        self.firstName = firstName
        self.lastName = lastName
    }
}

//创建一个Person的实例
var p = Person()


//实例方法是返回函数的类型方法
//这个报错了,跟书上说的不一样
//let changeName = Person.changeTo

p.changeTo(firstName: "John", lastName: "Gallagher")
p.firstName
